<!---->
<template>
    <div class="page_editfuken">
        <common-header :title="'复垦情况编辑'">
            <span slot="overwrite-left"></span>
        </common-header>
        <div class="btn-save" @click="saveLandTransferInfo">保存</div>
        <div class="pages-main" style="height: calc( 100vh - 45px)">
            <div class="item-info">
                <div class="item-item">
                    <x-input title="复垦面积(亩)" type="number" v-model="info.refarmingarea"
                             placeholder="请输入复垦面积(亩)">
                    </x-input>
                </div>
                <div class="item-item">
                    <x-input title="复垦区域" type="text" v-model="info.refarmingregion"
                             placeholder="请输入复垦区域">
                    </x-input>
                </div>
                <div class="item-item">
                    <x-input title="损毁原因" type="text" v-model="info.destroyreason"
                             placeholder="请输入损毁原因">
                    </x-input>
                </div>
                <div class="item-item">
                    <x-input title="复垦补助(元)" type="number" v-model="info.refarmingamount"
                             placeholder="请输入复垦补助">
                    </x-input>
                </div>
                <div class="item-item">
                    <datetime  :min-year="1900" title="补偿发放时间" placeholder="请选择补偿发放时间" v-model="sendtime"></datetime>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import resident from '../../services/resident'
    import {XInput, Selector, Datetime} from 'vux'
    import {checkNumber} from '../../utils/validate'

    export default {
        name: "editfuken",
        components: {
            XInput, Selector, Datetime
        },
        data() {
            return {
                id:this.$route.query.id,
                sendtime: this.$route.query.sendtime,
                info: {
                    familyid: this.$route.query.familyid,
                    villagecode:this.$route.query.villagecode,
                    refarmingarea: this.$route.query.refarmingarea,
                    refarmingregion: this.$route.query.refarmingregion,
                    destroyreason: this.$route.query.destroyreason,
                    refarmingamount: this.$route.query.refarmingamount,
                    sendtime: '',
                },
            }
        },

        watch: {},
        methods: {
            // 保存信息
            saveLandTransferInfo() {
                let param = {
                    refarmingarea: '请输入正确的复垦面积（数字类型且最多保留两位小数）',
                    refarmingregion: '请输入复垦区域',
                    destroyreason: '请输入损毁原因',
                    refarmingamount: '请输入正确复垦补助（数字类型且最多保留两位小数）',
                    sendtime: '请选择补偿发放时间',
                }
                for(let i in param){
                    if(i === 'sendtime'){
                        if(!this.sendtime){
                            this.$vux.toast.show({
                                text:param[i],
                                type:'text',
                                position: 'middle',
                            })
                            return ;
                        }
                    }else{
                        if(!this.info[i]){
                            this.$vux.toast.show({
                                text:param[i],
                                type:'text',
                                position: 'middle',
                            })
                            return ;
                        }
                    }

                }

                if(!checkNumber(this.info.refarmingarea,'复垦面积')){
                    return
                }
                if(!checkNumber(this.info.refarmingamount,'复垦补助')){
                    return
                }

                this.info.sendtime  = this.sendtime + ' ' + '00:00:00';
                if(this.id){
                    this.info =Object.assign(this.info,{id:this.id})
                }
                let _param = this.$tools.invokeUAF('resident/saveRefarmingInfo', this.info)
                resident.saveRefarmingInfo(_param).then(res => {
                })
            },
        },
    };
</script>

<style lang="less" rel="stylesheet/less" type="text/css">
    .page_editfuken {
    }

</style>
